package com.wjk.kylin.id.server.transactional;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 事务执行器
 * </p>
 *
 * @author wangjinkui
 * @since 2022-08-28
 */
@Slf4j
@Service
public class TransactionalHandle {

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean execute(TransactionalFunction function) {
        log.info("start transactional execute method");
        boolean flag = function.run();
        log.info("end transactional execute method flag:{}", flag);
        return flag;
    }
}
